package com.study.manage.dal;

import java.util.List;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import com.study.manage.domain.Discount;
import com.study.manage.domain.enumm.DiscountType;
import com.study.manage.domain.enumm.LiveDieState;

public interface DiscountRepository extends PagingAndSortingRepository<Discount, Long> {

    List<Discount> findByTypeAndExtIdAndState(DiscountType type, Long evaluateId,
            LiveDieState state);

    int countByBlogIdAndState(Long blogId, LiveDieState state);


    @Query("select t from Discount t where t.state=0 and (t.type=:type or :type is null) and t.blogId=:blogId")
    Page<Discount> findByTypeAndBlogId(@Param("type") DiscountType type,
            @Param("blogId") Long blogId, Pageable pageable);

}
